package com.mongdbtokuduswagger.config;

import com.mongdbtokuduswagger.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author Daft_V
 */
@Configuration
@Slf4j
public class PrimaryRedisConfig extends AbstractRedisConfig {
    @Value("${spring.redis.database}")
    private int dbIndex;

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private int port;

    @Value("${spring.redis.password}")
    private String password;

    @Value("${spring.redis.timeout}")
    private int timeout;


    @Primary
    @Bean(name = "primaryRedisUtil")
    @Override
    public RedisUtil getRedisUtil() {
        RedisTemplate redisTemplate = new RedisTemplate();
        initDomainRedisTemplate(redisTemplate,JedisConnectionFactory(host, password, port, timeout));
        RedisUtil redisUtil = new RedisUtil();
        redisUtil.setRedisTemplate(redisTemplate);
        return redisUtil;
    }
}
